package org.m3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class OllImage  extends Activity implements OnClickListener {

	protected static final String OUTPUT_PARAMS = null;

	private MediaPlayer mp;
	public static Integer[] Imgid = {
	            R.drawable.cow, R.drawable.cat,
	            R.drawable.chicken, R.drawable.dog,
	            R.drawable.donkey, R.drawable.duck,
	           
	    };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.oll_image);
                       
        Button btnHome = (Button) findViewById(R.id.btnHome);
        Button btnImageLoad = (Button) findViewById(R.id.btnImageLoad);
        
        btnHome.setOnClickListener(new OnClickListener() {
        	@Override
			public void onClick(View arg0) {
        		if(mp!=null) mp.stop();
				finish();
			}
        });
        
        btnImageLoad.setOnClickListener(new OnClickListener() {
        	@Override
			public void onClick(View arg0) {
	        	Intent intent = new Intent(OllImage.this, ImageLoad.class);
	        	startActivity(intent);
			}
        });
        
        
      /*  imgView = (ImageView)findViewById(R.id.ImageView01);
        imgView.setImageResource(Imgid[0]);

        gallery = (Gallery) findViewById(R.id.examplegallery);
        gallery.setAdapter(new AddImgAdp(this));

        gallery.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                imgView.setImageResource(Imgid[position]);
            }

        });*/
          
        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
        	@Override
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
       	        Intent intent = new Intent(OllImage.this, Home.class);
        	    intent.putExtra("imgId", position);
       	        startActivityForResult(intent, 0);
                
                /*Intent intent = new Intent();
                intent.setClass(OllImage.this, Home.class);
	        	//startActivityForResult(intent, position);
                //intent.putExtra(Home.EXT_COLS, position); 

                getPosition(position);
                

                startActivity(intent);
                finish();*/
            }
        });

    }
    
       
    /*

    public class AddImgAdp extends BaseAdapter {

        int GalItemBg;
        private Context cont;

        public AddImgAdp(Context c) {

            cont = c;
            TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
            GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
            typArray.recycle();
        }

        public int getCount() {
            return Imgid.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }


        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imgView = new ImageView(cont);
            imgView.setImageResource(Imgid[position]);

            imgView.setLayoutParams(new Gallery.LayoutParams(100, 100));
            //imgView.setScaleType(ImageView.ScaleType.FIT_XY);
            imgView.setBackgroundResource(GalItemBg);

            return imgView;

        }

    }*/

  
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}

}
